home *** CD-ROM | disk | FTP | other *** search
- Path: news1.erols.com!newsmaster@erols.com
- From: mnettles@erols.com (Mike Nettles)
- Newsgroups: comp.lang.c++
- Subject: Help: Opening Dynamic number of input files
- Date: Fri, 29 Mar 1996 15:27:07 GMT
- Organization: Erols Internet Services
- Message-ID: <4jfmqa$s95@news6.erols.com>
- NNTP-Posting-Host: ppp67.erols.com
- X-Newsreader: Forte Free Agent 1.0.82
-
- Suggestion, pointers, and / or samples sought.
-
-
- I am trying to write a sort routine that do to memory limitations
- swaps to disk files. Right now the program will read in a section of
- the information to be sorted, sort the information and the write the
- section to a temp file. The next sections is then read in, sorted,
- and written to another temp file, etc.
-
- My problem comes once all of the sort files are written, a need to
- combine them to make a sorted list. this is easy enough as all I need
- to do is open each file, read the first argument in and the output the
- lowest value and read the next one in.
-
- My problem comes in opening a dynamic number of input streams. I
- can't seem to find a way to get it to work. Can anybody give me some
- ideas, or perhaps a better way to do a very large sort. An example of
- what I am trying to do, in pseuda code, is below.
-
- int combine_sort_files(int num_sort_files) {
-
- ifstream input[num_sort_files);
- ofstream output ("sorted.dat");
-
- for (int tmp=0;tmp<num_sort_files;tmp++) {
- input[tmp].open ("sortfile#")
- }
- /* note code left out in above to convert filename from int tmp into
- char []*/
- ...
- /* rest of program follows */
-
-
- The above would be the way I'd prefer to do it. The only way i have
- been able to get it to work is hard code a maximum number of input
- files by putting a constant as in 'ifstream input[const value]; '
-
- I figure to do what I want I'll need to make a pointer and then use
- new to dynamically allocate the memory, but I haven't been able to
- figure how to get this to wrk.
-
-
- Any help is appreciated
-
- ;-) Even if it is to RTFM, if you post which manual and what sections
-
-
- Please replay if possible by E-mail as my news server is intermittant
- at best.
-
-